<h1 id="apk">apk</h1>
<p>Alpine Linux 下的包管理工具</p>
<h2 id="使用实例">使用实例</h2>
<div class="sourceCode" id="cb1"><pre><code class="language-bash"><a class="sourceLine" id="cb1-1" data-line-number="1"><span class="ex">apk</span> install xxx</a>
<a class="sourceLine" id="cb1-2" data-line-number="2"><span class="ex">apk</span> search xxx <span class="co"># 支持正则</span></a>
<a class="sourceLine" id="cb1-3" data-line-number="3"><span class="ex">apk</span> info xxx <span class="co"># 查看包的详细信息</span></a>
<a class="sourceLine" id="cb1-4" data-line-number="4"><span class="ex">apk</span> show <span class="co"># list local package</span></a>
<a class="sourceLine" id="cb1-5" data-line-number="5"><span class="co"># 卸载并删除 包</span></a>
<a class="sourceLine" id="cb1-6" data-line-number="6"><span class="ex">apk</span> del openssh openntp vim</a></code></pre></div>
<h3 id="升级">升级</h3>
<p>upgrade命令升级系统已安装的所以软件包（一般包括内核），当然也可指定仅升级部分软件包（通过-u或–upgrade选择指定）。</p>
<div class="sourceCode" id="cb2"><pre><code class="language-bash"><a class="sourceLine" id="cb2-1" data-line-number="1"><span class="ex">apk</span> update <span class="co"># 更新最新本地镜像源</span></a>
<a class="sourceLine" id="cb2-2" data-line-number="2"><span class="ex">apk</span> upgrade <span class="co"># 升级软件</span></a>
<a class="sourceLine" id="cb2-3" data-line-number="3"><span class="ex">apk</span> add --upgrade busybox <span class="co"># 指定升级部分软件包</span></a></code></pre></div>
<h3 id="搜索">搜索</h3>
<div class="sourceCode" id="cb3"><pre><code class="language-bash"><a class="sourceLine" id="cb3-1" data-line-number="1"><span class="ex">apk</span> search <span class="co"># 查找所以可用软件包</span></a>
<a class="sourceLine" id="cb3-2" data-line-number="2"><span class="ex">apk</span> search -v <span class="co"># 查找所以可用软件包及其描述内容</span></a>
<a class="sourceLine" id="cb3-3" data-line-number="3"><span class="ex">apk</span> search -v <span class="st">&#39;acf*&#39;</span> <span class="co"># 通过软件包名称查找软件包</span></a>
<a class="sourceLine" id="cb3-4" data-line-number="4"><span class="ex">apk</span> search -v -d <span class="st">&#39;docker&#39;</span> <span class="co"># 通过描述文件查找特定的软件包</span></a></code></pre></div>
<h3 id="查看包信息">查看包信息</h3>
<p>info命令用于显示软件包的信息。</p>
<div class="sourceCode" id="cb4"><pre><code class="language-bash"><a class="sourceLine" id="cb4-1" data-line-number="1"><span class="ex">apk</span> info <span class="co"># 列出所有已安装的软件包</span></a>
<a class="sourceLine" id="cb4-2" data-line-number="2"><span class="ex">apk</span> info -a zlib <span class="co"># 显示完整的软件包信息</span></a>
<a class="sourceLine" id="cb4-3" data-line-number="3"><span class="ex">apk</span> info --who-owns /sbin/lbu <span class="co"># 显示指定文件属于的包</span></a></code></pre></div>
<h2 id="笔记">笔记</h2>
<p>还是蛮喜欢 alpine 的，简单纯粹</p>
<div class="sourceCode" id="cb5"><pre><code class="language-bash"><a class="sourceLine" id="cb5-1" data-line-number="1"><span class="ex">apk</span> add iproute2 <span class="co"># ss vs netstat</span></a>
<a class="sourceLine" id="cb5-2" data-line-number="2"><span class="ex">ss</span> -ptl</a>
<a class="sourceLine" id="cb5-3" data-line-number="3"><span class="ex">apk</span> add drill <span class="co"># drill vs nslookup&amp;dig</span></a>
<a class="sourceLine" id="cb5-4" data-line-number="4"></a>
<a class="sourceLine" id="cb5-5" data-line-number="5"><span class="ex">crond</span> <span class="co"># 开启 cron 服务</span></a>
<a class="sourceLine" id="cb5-6" data-line-number="6"><span class="ex">crontab</span> -l -e</a>
<a class="sourceLine" id="cb5-7" data-line-number="7"></a>
<a class="sourceLine" id="cb5-8" data-line-number="8"><span class="ex">apk</span> add xxx</a>
<a class="sourceLine" id="cb5-9" data-line-number="9"><span class="ex">apk</span> search -v xxx</a>
<a class="sourceLine" id="cb5-10" data-line-number="10"><span class="ex">apk</span> info -a xxx</a>
<a class="sourceLine" id="cb5-11" data-line-number="11"><span class="ex">apk</span> info</a>
<a class="sourceLine" id="cb5-12" data-line-number="12"><span class="bu">echo</span> -e <span class="st">&quot;http://mirrors.aliyun.com/alpine/v3.6/main\nhttp://mirrors.aliyun.com/alpine/v3.6/community&quot;</span> <span class="op">&gt;</span> /etc/apk/repositories</a>
<a class="sourceLine" id="cb5-13" data-line-number="13"><span class="ex">apk</span> update</a>
<a class="sourceLine" id="cb5-14" data-line-number="14"></a>
<a class="sourceLine" id="cb5-15" data-line-number="15"><span class="co"># storage</span></a>
<a class="sourceLine" id="cb5-16" data-line-number="16"><span class="ex">ibu</span> <span class="co"># alpine local backup</span></a>
<a class="sourceLine" id="cb5-17" data-line-number="17"></a>
<a class="sourceLine" id="cb5-18" data-line-number="18"><span class="co"># network</span></a>
<a class="sourceLine" id="cb5-19" data-line-number="19"><span class="bu">echo</span> <span class="st">&quot;shortname&quot;</span> <span class="op">&gt;</span> /etc/hostname</a>
<a class="sourceLine" id="cb5-20" data-line-number="20"><span class="fu">hostname</span> -F /etc/hostname</a>
<a class="sourceLine" id="cb5-21" data-line-number="21"><span class="ex">/etc/hosts</span></a>
<a class="sourceLine" id="cb5-22" data-line-number="22"><span class="ex">/etc/resolv.conf</span> <span class="co"># conig DNS</span></a>
<a class="sourceLine" id="cb5-23" data-line-number="23"><span class="ex">modprobe</span> ipv6 <span class="co"># enable ipv6</span></a>
<a class="sourceLine" id="cb5-24" data-line-number="24"><span class="bu">echo</span> <span class="st">&quot;ipv6&quot;</span> <span class="op">&gt;&gt;</span> /etc/modules</a>
<a class="sourceLine" id="cb5-25" data-line-number="25"><span class="ex">iface</span> <span class="co"># config interface</span></a>
<a class="sourceLine" id="cb5-26" data-line-number="26"><span class="ex">apk</span> add iptables ip6tables iptables-doc</a>
<a class="sourceLine" id="cb5-27" data-line-number="27"><span class="ex">/etc/init.d/networking</span> restart <span class="co"># activate change</span></a>
<a class="sourceLine" id="cb5-28" data-line-number="28"><span class="ex">apke</span> add iputils <span class="co"># IPv6 traceroute</span></a>
<a class="sourceLine" id="cb5-29" data-line-number="29"><span class="ex">traceroute6</span> ipv6.google.com</a>
<a class="sourceLine" id="cb5-30" data-line-number="30"><span class="ex">awall</span> <span class="co"># alpine wall</span></a>
<a class="sourceLine" id="cb5-31" data-line-number="31"><span class="co"># setup a openvpn server</span></a>
<a class="sourceLine" id="cb5-32" data-line-number="32"></a>
<a class="sourceLine" id="cb5-33" data-line-number="33"><span class="co"># post-install</span></a>
<a class="sourceLine" id="cb5-34" data-line-number="34"><span class="ex">/etc/apk/repositories</span></a>
<a class="sourceLine" id="cb5-35" data-line-number="35"><span class="ex">apk</span> add cherokee --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted</a>
<a class="sourceLine" id="cb5-36" data-line-number="36"><span class="ex">apk</span> search -v --description <span class="st">&#39;NTP&#39;</span> <span class="co"># show description and search from description</span></a>
<a class="sourceLine" id="cb5-37" data-line-number="37"><span class="ex">apk</span> info -a zlib</a>
<a class="sourceLine" id="cb5-38" data-line-number="38"><span class="ex">apk</span> info -vv<span class="kw">|</span><span class="fu">sort</span></a>
<a class="sourceLine" id="cb5-39" data-line-number="39"><span class="ex">apk</span> info -r -R <span class="co"># require / depency</span></a>
<a class="sourceLine" id="cb5-40" data-line-number="40"><span class="ex">apk</span> version -v -l <span class="st">&#39;&lt;&#39;</span> <span class="co"># show available updates</span></a>
<a class="sourceLine" id="cb5-41" data-line-number="41"><span class="ex">apk</span> upgrade -U -a</a>
<a class="sourceLine" id="cb5-42" data-line-number="42"><span class="ex">apk</span> add -u xxx <span class="co"># update xxx</span></a>
<a class="sourceLine" id="cb5-43" data-line-number="43"></a>
<a class="sourceLine" id="cb5-44" data-line-number="44"><span class="ex">/etc/runlevels</span> <span class="co"># runlevel</span></a>
<a class="sourceLine" id="cb5-45" data-line-number="45"><span class="ex">apk</span> add openrc <span class="co"># use openrc for init system</span></a>
<a class="sourceLine" id="cb5-46" data-line-number="46"><span class="ex">rc-update</span> add xxx <span class="co"># set to start on</span></a>
<a class="sourceLine" id="cb5-47" data-line-number="47"><span class="ex">rc-service</span> xxx start <span class="co"># equal -&gt; /etc/init.d/xxx start</span></a>
<a class="sourceLine" id="cb5-48" data-line-number="48"><span class="ex">rc-status</span></a>
<a class="sourceLine" id="cb5-49" data-line-number="49"></a>
<a class="sourceLine" id="cb5-50" data-line-number="50"><span class="ex">adduser</span> xxx</a>
<a class="sourceLine" id="cb5-51" data-line-number="51"><span class="fu">passwd</span> xxx</a>
<a class="sourceLine" id="cb5-52" data-line-number="52"></a>
<a class="sourceLine" id="cb5-53" data-line-number="53"><span class="ex">apk</span> add ansible <span class="co"># server</span></a>
<a class="sourceLine" id="cb5-54" data-line-number="54"><span class="fu">ssh-keygen</span></a>
<a class="sourceLine" id="cb5-55" data-line-number="55"><span class="ex">/etc/ansible/hosts</span></a>
<a class="sourceLine" id="cb5-56" data-line-number="56"><span class="ex">apk</span> add python <span class="co"># node</span></a>
<a class="sourceLine" id="cb5-57" data-line-number="57"><span class="ex">ssh-copy-id</span></a>
<a class="sourceLine" id="cb5-58" data-line-number="58"></a>
<a class="sourceLine" id="cb5-59" data-line-number="59"><span class="ex">apk</span> add man man-pages mdocml-apropos less less-doc</a>
<a class="sourceLine" id="cb5-60" data-line-number="60"><span class="bu">export</span> <span class="va">PAGER=</span>less</a>
<a class="sourceLine" id="cb5-61" data-line-number="61"><span class="ex">/etc/rc.conf</span> <span class="co"># /etc/rc.conf -&gt; funny character</span></a>
<a class="sourceLine" id="cb5-62" data-line-number="62"><span class="ex">apk</span> add bash bash-doc bash-completion <span class="co"># bash</span></a>
<a class="sourceLine" id="cb5-63" data-line-number="63"><span class="ex">apk</span> add util-linux pciutils usbutils coreutils binutils findutils grep <span class="co"># grep / awk</span></a>
<a class="sourceLine" id="cb5-64" data-line-number="64"><span class="ex">apk</span> add build-base gcc abuild binutils binutils-doc gcc-doc <span class="co"># compile</span></a>
<a class="sourceLine" id="cb5-65" data-line-number="65"><span class="ex">apk</span> add cmake cmake-doc extra-cmake-modules extra-cmake-modules-doc</a>
<a class="sourceLine" id="cb5-66" data-line-number="66"><span class="ex">apk</span> add ccache ccache-doc</a>
<a class="sourceLine" id="cb5-67" data-line-number="67"></a>
<a class="sourceLine" id="cb5-68" data-line-number="68"><span class="ex">apk</span> add docker <span class="co"># docker</span></a>
<a class="sourceLine" id="cb5-69" data-line-number="69"><span class="ex">rc-update</span> add docker boot</a>
<a class="sourceLine" id="cb5-70" data-line-number="70"><span class="ex">rc-service</span> docker start</a>
<a class="sourceLine" id="cb5-71" data-line-number="71"><span class="ex">apk</span> add py-pip</a>
<a class="sourceLine" id="cb5-72" data-line-number="72"><span class="ex">pip</span> install docker-compose</a>
<a class="sourceLine" id="cb5-73" data-line-number="73"><span class="fu">ln</span> -s /usr/bin/docker-compose /usr/bin/doc</a>
<a class="sourceLine" id="cb5-74" data-line-number="74"></a>
<a class="sourceLine" id="cb5-75" data-line-number="75"><span class="co"># application</span></a>
<a class="sourceLine" id="cb5-76" data-line-number="76"><span class="ex">apk</span> add openssh <span class="co"># ssh</span></a>
<a class="sourceLine" id="cb5-77" data-line-number="77"><span class="ex">rc-update</span> add sshd</a>
<a class="sourceLine" id="cb5-78" data-line-number="78"><span class="ex">/etc/init.d/sshd</span> start</a>
<a class="sourceLine" id="cb5-79" data-line-number="79"><span class="ex">/etc/sshd_config</span></a>
<a class="sourceLine" id="cb5-80" data-line-number="80"><span class="ex">apk</span> add dropbear <span class="co"># another openssh implementation</span></a></code></pre></div>
